package com.zenithmind.library.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 借阅状态枚举
 * 
 * @author ZenithMind
 * @since 2024-06-14
 */
@Getter
@AllArgsConstructor
public enum BorrowStatus {
    
    /**
     * 借阅中
     */
    BORROWING(0, "借阅中"),
    
    /**
     * 已归还
     */
    RETURNED(1, "已归还"),
    
    /**
     * 逾期
     */
    OVERDUE(2, "逾期"),
    
    /**
     * 已续借
     */
    RENEWED(3, "已续借"),
    
    /**
     * 丢失
     */
    LOST(4, "丢失"),
    
    /**
     * 损坏
     */
    DAMAGED(5, "损坏");
    
    private final Integer code;
    private final String description;
    
    /**
     * 根据代码获取枚举
     */
    public static BorrowStatus getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (BorrowStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
    
    /**
     * 判断是否为借阅中状态
     */
    public boolean isBorrowing() {
        return this == BORROWING || this == OVERDUE || this == RENEWED;
    }
    
    /**
     * 判断是否已完成（归还或其他终结状态）
     */
    public boolean isCompleted() {
        return this == RETURNED || this == LOST || this == DAMAGED;
    }
}
